<!--

/*
* Copyright (C) 2005-2013 University of Sydney
*
* Licensed under the GNU License, Version 3.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

/**
* brief description of file
*
* @author      Tom Murtagh
* @author      Kim Jackson
* @author      Ian Johnson   <ian.johnson@sydney.edu.au>
* @author      Stephen White   <stephen.white@sydney.edu.au>
* @author      Artem Osmakov   <artem.osmakov@sydney.edu.au>
* @copyright   (C) 2005-2013 University of Sydney
* @link        http://Sydney.edu.au/Heurist
* @version     3.1.0
* @license     http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0
* @package     Heurist academic knowledge management system
* @subpackage  !!!subpackagename for file such as Administration, Search, Edit, Application, Library
*/

-->
<!--

/**
 * filename, brief description, date of creation, by whom
 * @copyright (C) 2005-2010 University of Sydney Digital Innovation Unit.
 * @link: http://HeuristScholar.org
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
 * @package Heurist academic knowledge management system
 * @todo
 **/

-->
<html>
	<!-- relationshipsTab.html

	Copyright 2005 - 2010 University of Sydney Digital Innovation Unit
	This file is part of the Heurist academic knowledge management system (http://HeuristScholar.org)
	mailto:info@heuristscholar.org

	Concept and direction: Ian Johnson.
	Developers: Tom Murtagh, Kim Jackson, Steve White, Steven Hayes,
				Maria Shvedova, Artem Osmakov, Maxim Nikitin.
	Design and advice: Andrew Wilson, Ireneusz Golka, Martin King.

	Heurist is free software; you can redistribute it and/or modify it under the terms of the
	GNU General Public License as published by the Free Software Foundation; either version 3
	of the License, or (at your option) any later version.

	Heurist is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
	even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License along with this program.
	If not, see <http://www.gnu.org/licenses/>
	or write to the Free Software Foundation,Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

	-->
<head>
	<link rel=stylesheet href="../../../common/css/global.css">
	<link rel=stylesheet href="../../../common/css/edit.css">
	<link rel="stylesheet" type="text/css" href="../../../common/css/calendar.css" />
	<script type="text/javascript" src="../../../external/jquery/jquery.js"></script>
	<script type="text/javascript" src="../../../common/js/hintDiv.js"></script>

</head>
<body class="editTab">
		<script src="../../../common/js/utilsLoad.js"></script>
		<script src="../relationshipsObjectLibrary.js"></script>
		<script src="../../../common/php/displayPreferences.php"></script>

		<script type="text/javascript" src="../../../common/js/calendarViewer.js"></script>
		<script type="text/javascript" src="../../../common/js/calendar.js"></script>

		<script>

			function onshow() {
				top.HEURIST.edit.calendarViewer = calendarViewer;
				var elt = document.getElementById("relationship-type");
				setTimeout(function() {
					try {
						if (elt) elt.focus()
					} catch (e) {}
				}, 0);
			}
		</script>

		<div><H2>Related records</H2></div>

		<div id=relations></div>
		<div id=relations-tbody style="width:100%"></div>

		<script>
			document.write('<form id=relations-form jsonAction="'+top.HEURIST.basePath+'records/relationships/saveRelationships.php"></form>');
		</script>
		<script>

			function changed() { /* top.HEURIST.edit.changed("relationships"); */ }

			function changeNotification(cmd, relID) {
				if (cmd == "delete") {
					deleteInput = document.createElement("input");
					deleteInput.type = "hidden";
					deleteInput.name = "delete[]";
					deleteInput.value = relID;
					document.getElementById("relations-form").appendChild(deleteInput); // saw TODO separate
					top.HEURIST.edit.changed("relationships");
					top.HEURIST.edit.changed("public");
				}
			}

			document.forms[0].heuristSubmit = function() {
				top.HEURIST.util.xhrFormSubmit(document.forms[0], function(json) {
					var vals = eval(json.responseText);
					if (vals) top.HEURIST.edit.record.relatedRecords = vals;
					window.location.reload();
				});
			};

			document.forms[0].heuristForceSubmit = function() {
				relManager.saveAllOpen();
			};

			var bibInput = document.createElement("input");
			bibInput.type = "hidden";
			bibInput.name = "recID";
			bibInput.value = top.HEURIST.edit.record.bibID;
			document.getElementById("relations-form").appendChild(bibInput);

			var relatedRecords = top.HEURIST.edit.record.relatedRecords;
			var relationsBody = document.getElementById("relations-tbody");
			var relManager = new top.RelationManager(relationsBody,top.HEURIST.edit.record, relatedRecords,0,changeNotification,false,true);

		</script>

	</body>
</html>
